package com.itboye.ihomebank.key;

import java.util.ArrayList;
import java.util.List;

import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.FrameLayout.LayoutParams;

import com.itboye.ihomebank.R;
import com.itboye.ihomebank.adapter.YongHuGuanLiAdapter;
import com.itboye.ihomebank.base.BaseOtherActivity;
import com.itboye.ihomebank.bean.YongHuGuanLiBean;
import com.itboye.ihomebank.custom.XListView;
/**
 * 钥匙用户管理
 *
 */
public class ActivityYongHuGuanLi extends BaseOtherActivity {
	XListView yonghu_listview;
	
	ImageView key_title_finish;
	TextView key_title_title;
	RelativeLayout key_title_xuanze;
	TextView key_title_xuan;
	
	PopupWindow window;
	
	YongHuGuanLiAdapter adapter;
	
	List<YongHuGuanLiBean> list;
	
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.key_title_finish:
			finish();
			break;
		case R.id.key_title_xuanze://切换
			PuPoWindow(v);
			break;

		default:
			break;
		}

	}

	@Override
	protected int layout_id() {
		// TODO Auto-generated method stub
		return R.layout.activity_yonghu_guanli;
	}

	@Override
	protected void onInitController() {
		// TODO Auto-generated method stub

	}

	@Override
	protected void onInit() {
		key_title_title.setText("用户管理");
		key_title_xuan.setText("电子钥匙");
		
		list=new ArrayList<YongHuGuanLiBean>();
		
		adapter=new YongHuGuanLiAdapter(this, list, R.layout.item_yonghu_guanli);
		yonghu_listview.setAdapter(adapter);
		
		for (int i = 0; i < 3; i++) {
			YongHuGuanLiBean bean=new YongHuGuanLiBean();
			bean.setName("钥匙id"+"-"+i);
			
			list.add(bean);
		}
		
		adapter.notifyDataSetChanged();
	}

	@Override
	protected void onReadIntent(Bundle bundle) {
		// TODO Auto-generated method stub

	}
	
	/**
	 * 切换框
	 * @param v
	 */
	private void PuPoWindow(View v) {

		View view = LayoutInflater.from(this).inflate(
				R.layout.item_yonghu_qiehuan, null);
		TextView yopnghu_yaoshi = (TextView) view.findViewById(R.id.yopnghu_yaoshi);
		TextView yopnghu_pass = (TextView) view.findViewById(R.id.yopnghu_pass);

		yopnghu_yaoshi.setOnClickListener(this);
		yopnghu_pass.setOnClickListener(this);
		
		window = new PopupWindow(view, LayoutParams.WRAP_CONTENT,
				LayoutParams.WRAP_CONTENT);
		window.setOutsideTouchable(true);
		window.setBackgroundDrawable(new BitmapDrawable());
		window.showAsDropDown(v);
	}

}
